﻿using BCCommon;
using BCDto.TMS.Packing.PackingConfig;
using BCService.TMS.Packing.PackingConfig;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;

namespace BCTMSRESTful.Controllers.Management.TMS.Packing.PackingConfig
{
    /// <summary>
    /// 包装材料配置
    /// </summary>
    [Route("api/v1/sim/[controller]")]
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    public class PackingConfigController : ManagementBaseController
    {
        #region var
        private readonly IPackingConfigService packingConfigService;
        #endregion


        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary> 
        public PackingConfigController(IPackingConfigService packingConfigService)
        {
            this.packingConfigService = packingConfigService;
        }
        #endregion

        #region POST 添加 添加新包装材料配置记录 包装材料配置数据模型

        /// <summary>
        /// 添加包装材料配置记录
        /// </summary>
        /// <param name="requestDto">包装材料配置记录添加信息</param>
        /// <response code="201">添加包装材料配置记录</response>
        /// <returns></returns>
        [Log("添加新包装材料配置记录")]
        [HttpPost]
        [ProducesResponseType(typeof(PackingConfigDto), 201)]
        public IActionResult Post([FromBody] PackingConfigRequestDto requestDto)
        {
            var result = this.packingConfigService.Add(requestDto, this.Admin);
            return Ok(result);
        }

        #endregion

        #region PUT 修改 修改包装材料配置记录  包装材料配置数据模型

        /// <summary>
        /// 修改包装材料配置记录
        /// </summary>
        /// <param name="packingConfigId">包装材料配置Id</param>
        /// <param name="putDto">包装材料配置记录修改信息</param>
        /// <response code="200">修改包装材料配置记录</response>
        /// <returns></returns>
        [Log("修改包装材料配置记录")]
        [HttpPut("{packing_config_id}")]
        [ProducesResponseType(typeof(PackingConfigDto), 200)]
        public IActionResult Put([FromRoute(Name = "packing_config_id")]int packingConfigId,
            [FromBody] PackingConfigPutDto putDto)
        {
            var result = this.packingConfigService.Update(this.Admin, packingConfigId, putDto);
            return this.Ok(result);
        }
        #endregion

        #region 删除 删除包装材料配置纪录

        /// <summary>
        /// 删除包装材料配置记录
        /// </summary>
        /// <param name="packingConfigId">包装材料配置Id</param>
        /// <response code="204">删除包装材料配置记录</response>
        /// <returns></returns>
        [Log("删除包装材料配置记录")]
        [HttpDelete("{packing_config_id}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "packing_config_id")] int packingConfigId)
        {
            this.packingConfigService.Delete(this.Admin, packingConfigId);
            return NoContent();
        }
        #endregion

        /// <summary>
        /// 启用/禁用包装材料配置
        /// </summary>
        /// <param name="packingConfigId">包装材料配置Id</param>
        /// <param name="enabled">是否启用</param>
        /// <response code="200">启用/禁用包装材料配置</response>
        /// <returns></returns>
        [HttpPut("[action]/{packing_config_id}/{enabled}")]
        [ProducesResponseType(typeof(PackingConfigDto), 200)]
        [Log("启用/禁用包装材料配置")]
        public IActionResult Enabled([FromRoute(Name = "packing_config_id")] int packingConfigId,
            [FromRoute(Name = "enabled")] bool enabled)
        {
            var result = this.packingConfigService.UpdateEnabled(this.Admin, packingConfigId, enabled);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取包装材料配置记录
        /// </summary>
        /// <param name="packingCategoryConfigId">包装材料分类配置Id</param>
        /// <param name="packingTitle">包装材料标题</param>
        /// <param name="enabled">是否启用</param>
        /// <param name="createStartDate">创建开始日期</param>
        /// <param name="createEndDate">创建结束日期</param>
        /// <param name="pageIndex">页号</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <response code="200">获取包装材料配置记录</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<PackingConfigViewDto>), 200)]
        public IActionResult Query([FromQuery(Name = "packing_category_config_id")]int? packingCategoryConfigId,
            [FromQuery(Name = "packing_title")]string packingTitle,
            [FromQuery(Name = "enabled")]bool? enabled,
            [FromQuery(Name = "create_start_date")] DateTime? createStartDate,
            [FromQuery(Name = "create_end_date")] DateTime? createEndDate,
            [FromQuery(Name = "page_index")] int pageIndex = 1,
            [FromQuery(Name = "page_size")] int pageSize = 10)
        {
            var result = this.packingConfigService.Query(this.Admin, packingCategoryConfigId, packingTitle, enabled, createStartDate, createEndDate, pageIndex, pageSize);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取包装材料配置记录列表
        /// </summary>
        /// <param name="packingCategoryConfigId">包装材料分类配置Id</param>
        /// <param name="packingTitle">包装材料标题</param>
        /// <param name="enabled">是否启用</param>
        /// <response code="200">获取包装材料配置记录列表</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<PackingConfigDto>), 200)]
        public IActionResult List([FromQuery(Name = "packing_category_config_id")]int? packingCategoryConfigId,
            [FromQuery(Name = "packing_title")] string packingTitle,
            [FromQuery(Name = "enabled")]bool? enabled)
        {
            var result = this.packingConfigService.GetList(packingCategoryConfigId, packingTitle, enabled);
            return this.Ok(result);
        }
    }
}
